package thread;

/**
 * 常见的并发安全API：StringBuilder和StringBuffer
 * 1.StringBuilder不是并发安全的（是异步的），多线程场景下不能用
 * 2.StringBuffer是并发安全的（是同步），多线程场景时使用
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        //StringBuilder sb = new StringBuilder();
        StringBuffer sb = new StringBuffer();
        Thread t1 = new Thread(){
            public void run(){
                for (int i = 0; i < 10000; i++) {
                    sb.append("abc");
                }
            }
        };
        Thread t2 = new Thread(){
            public void run(){
                for (int i = 0; i < 10000; i++) {
                    sb.append("def");
                }
            }
        };
    }
}
